home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 8 / Revista CD Expert nº 08 CD1.iso / Utilitarios / Office / Where Is It / SETUP.EXE / %MAINDIR% / DescAPI / Sample / SampleModule.dpr < prev   
Encoding:
Text File  |  1999-04-11  |  5.1 KB  |  141 lines

  1. //============================================================================
  2. //                               SampleModule.DLL
  3. //                 WhereIsIt Description API Demontration Module
  4. //                         Robert Galle, November 1998
  5. //============================================================================
  6.  
  7. library SampleModule;
  8.  
  9. uses Windows;
  10.  
  11. {$INCLUDE DescAPI.inc}
  12.  
  13.  
  14. //****************************************************************************
  15. //                 Implementation of "Text file import" plugin
  16. //****************************************************************************
  17.  
  18. procedure ImportTextFile(const FileList, DescResult: PChar; RequireFileProc: TRequireFileProc);
  19.  
  20. // Plugin will import the first 5 lines of text from first specified description
  21. // file and use it as a description for parent item (folder or archive file).
  22.  
  23. // NOTE: This is a VERY simplified plugin. It does nothing special, and does
  24. // not include any special data checking or error recovery apart from the
  25. // most basic one. It should only be used as reference to Description API
  26. // implementation, not as a base for any "real" plugins.
  27.  
  28. const NumLines = 5;   // number of lines to import
  29.  
  30. var StoreFileMode, n: Integer;
  31.     TextFile: Text;
  32.     TextFilePath: PChar;
  33.     Line,Desc: string;
  34. begin
  35.   // FileList points here to a list of found files, not in any particular order.
  36.   // This list is actually a single stream of null-terminated strings, attached
  37.   // to each other, and an empty string ending the list, for example:
  38.   //  'README.TXT'#0'DESC.TXT'#0'DESC.NFO'#0'LICENSE.TXT'#0#0
  39.   // Each plugin should decide what to do with found files, and which one to
  40.   // use for importing. This sample plugin will just import the first file in
  41.   // the list.
  42.  
  43.   // Let's request the first file in the list from WhereIsIt
  44.   TextFilePath:=RequireFileProc(FileList);
  45.  
  46.   // plugin will open file as read-only, so opening should not fail even if
  47.   // file is already opened by some other program.
  48.   StoreFileMode:=FileMode;
  49.   FileMode:=0;   // read-only
  50.  
  51.    // try to open the file
  52.   AssignFile(TextFile,TextFilePath);
  53.   Reset(TextFile);
  54.  
  55.    // if something went wrong with opening the file, just leave the description
  56.   // alone and exit
  57.   if IOResult<>0 then Exit;
  58.  
  59.   try
  60.     // read the first <NumLines> and store them in Desc
  61.     n:=0;
  62.     Desc:='';
  63.     while not EOF(TextFile) and (n<NumLines) do begin
  64.       ReadLn(TextFile,Line);
  65.       Desc:=Desc+#13#10+Line;
  66.       Inc(n);
  67.     end;
  68.     // copy the description to where it is expected (DescResult buffer),
  69.     // but make sure not to exceed the maximum description buffer size
  70.     // specified with MaxDescLength constant!
  71.     LStrCpyN(DescResult,PChar(Desc),MaxDescLength-1);
  72.   finally
  73.     // just clean up an return
  74.     Close(TextFile);
  75.     FileMode:=StoreFileMode;
  76.   end;
  77. end;
  78.  
  79.  
  80. //****************************************************************************
  81. //                        Description API interface
  82. //****************************************************************************
  83.  
  84. procedure ModuleInfo(PluginName, Author, Version: PChar); stdcall;
  85. begin
  86.   // just provides some basic information about description module
  87.   LStrCpy(PluginName, 'WhereIsIt Sample Description Module');
  88.   LStrCpy(Author, 'Robert Galle');
  89.   LStrCpy(Version, '1.0');
  90. end;
  91.  
  92. procedure ConfigureProc(HInstance: THandle; OwnerWnd: THandle; PluginID: Word); stdcall;
  93. begin
  94.   // this one executes when user requests to configure plugin. In this sample
  95.   // it will just show a simple dialog with version information.
  96.   MessageBox(OwnerWnd,
  97.     PChar('Sample Description Module v1.0'+#13#13'Here could be implemented a '+
  98.           'special dialog where users could configure the plugin.'),
  99.     'About SampleModule.DLL',
  100.     MB_IconInformation+MB_OK);
  101. end;
  102.  
  103. procedure RegisterDescPlugins(RegisterPlugin: TRegisterPlugin); stdcall;
  104. begin
  105.    // register the plugin in WhereIsIt
  106.    RegisterPlugin(0, ptParentItem, 'Text files import', '*.TXT,*.NFO,READ.ME', ConfigureProc);
  107. end;
  108.  
  109. function ImportDesc_ParentItem(PluginID: Word; ParentName,FoundList,Desc: PChar;
  110.    RequireFileProc: TRequireFileProc): Boolean; stdcall;
  111. begin
  112.   // This procedure is called for each ptParentItem plugin in this module. It
  113.   // should check requested PluginID, and run the appropriate plugin. Available
  114.   // for plugins are a list of found description files, matching plugin's
  115.   // FileMask (FoundList parameter), and address of buffer where the extracted
  116.   // description is expected.
  117.  
  118.   // assume that description will be an empty string by default
  119.   Desc[0]:=#0;
  120.  // call appropriate plugin by the PluginID - not much choice, we only have
  121.   // one plugin in this sample
  122.   case PluginID of
  123.     0: if FoundList>'' then ImportTextFile(FoundList,Desc,RequireFileProc);
  124.   end;
  125.  
  126.   // function should return True if description was retrieved.
  127.   Result:= Desc>'';
  128. end;
  129.  
  130.  
  131. // The DLL library needs to export functions required by Description API
  132. exports
  133.   ModuleInfo╨o,
  134.   RegisterDescPlugins,
  135.   ImportDesc_ParentItem;
  136.  
  137. // That's it. Simple, eh?
  138.  
  139. begin
  140. end.
  141.